/*******************************************************************************
 * Copyright (c) 2008 Sylvain Sicard.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Sylvain Sicard - initial API and implementation
 ******************************************************************************/
package fr.jade.console.core;

import java.util.LinkedList;
import java.util.Map;

import org.objectweb.fractal.api.Component;

import fr.jade.base.JadeBaseObject;

public abstract class AbstractCommand extends JadeBaseObject implements Command {

  public void register(Map<String, Command>context){
    context.put(getName(), this);
  }
  
  protected Component getCurrent(Environment env) throws DisconnectedException{
    Component current = (Component)env.getEnvVar("current");
    if (current == null) throw new DisconnectedException();
    return current;
  }

  protected Component getRoot(Environment env) throws DisconnectedException{
    Component current = (Component)env.getEnvVar("root");
    if (current == null) throw new DisconnectedException();
    return current;
  }
  
  protected LinkedList<Component> getPwd(Environment env) throws DisconnectedException{
    LinkedList<Component> current = (LinkedList<Component>)env.getEnvVar("pwd");
    if (current == null) throw new DisconnectedException();
    return current;
  }
}
